package com.qf.store.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.store.entity.GoodsDetail;
import com.qf.store.mapper.GoodsDetailMapper;
import com.qf.store.service.GoodsDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author songfei
 * @Date 2021/10/7 18:15
 * @Version 1.0
 */
@Service
public class GoodsDetailServiceImpl implements GoodsDetailService {
    @Autowired
    private GoodsDetailMapper goodsDetailMapper;
    @Override
    public void update(GoodsDetail goodsDetail) {
        int i = goodsDetailMapper.updateByPrimaryKeySelective(goodsDetail);
        if(i!=1){
            System.out.println("购买失败");
            throw new RuntimeException("购买失败");
        }
    }

    @Override
    public PageInfo<GoodsDetail> findByIdAndPage(Integer page, Integer rows, Integer id) {
        //1.分页
        PageHelper.startPage(page,rows);
        //2.查询
        List<GoodsDetail> goodsDetailList = goodsDetailMapper.findById(id);
        //3.分装PageInfo
        PageInfo<GoodsDetail> pageInfo = new PageInfo<>(goodsDetailList);
        //4.返回
        return pageInfo;
    }
}
